package com.thf.exception.resolver;

import com.thf.exception.AjaxRequestException;
import com.thf.exception.InterceptorException;
import com.thf.exception.LoginException;
import com.thf.exception.TraditionRequestException;
import com.thf.model.ResultData;
import com.thf.util.ResultTool;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MyExceptionResolver {

    @ExceptionHandler(value= LoginException.class)
    public Object loginExceptionResolver(Exception e){
        /*
		 * 指定返回值的编码和内容类型，
		 并通过response的PrintWriter对象将自定义的返回值返回给调用方。
		 */
        e.printStackTrace();
//        Map<String,Object> map = new HashMap<>();
//        map.put("code", ResultTool.CODE_ERROR);
//        map.put("msg",e.getMessage());
        return new ResultData(ResultTool.CODE_ERROR,e.getMessage());

    }

    @ExceptionHandler(value= InterceptorException.class)
    public Object interceptorExceptionResolver(Exception e){

        System.out.println("处理没登陆");

        e.printStackTrace();

        return new ResultData(ResultTool.LOGIN_CODE_ERROR, ResultTool.LOGIN_CODE_ERROR_MSG);

    }

    @ExceptionHandler(value= AjaxRequestException.class)
    public Object ajaxRequestExceptionResolver(Exception e){

        e.printStackTrace();

        System.out.println("---------------------====================================");

        return new ResultData(ResultTool.CODE_ERROR, ResultTool.ERROR_CODE_MSG);

    }
    @ExceptionHandler(value= TraditionRequestException.class)
    public Object traditionRequestExceptionResolver(Exception e){

        e.printStackTrace();

        return new ResultData(ResultTool.EXCEPTION_CODE_ERROR,e.getMessage());

    }

    @ExceptionHandler(value= Exception.class)
    public Object exceptionResolver(Exception e){

        e.printStackTrace();

        return new ResultData(ResultTool.EXCEPTION_CODE_ERROR,e.getMessage());

    }
}





































